<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-header">
        <h2>欢迎回来</h2>
        <p>请登录您的账户</p>
      </div>
      
      <form class="login-form" @submit.prevent="handleLogin">
        <div class="form-group">
          <input
              type="text"
              v-model="username"
              placeholder="用户名"
              required
          >
          <span class="focus-border"></span>
        </div>

        <div class="form-group">
          <input
              type="password"
              v-model="password"
              placeholder="密码"
              required
          >
          <span class="focus-border"></span>
        </div>

        <div class="form-options">
          <label class="remember-me">
            <input type="checkbox" v-model="rememberMe">
            <span>记住我</span>
          </label>
          <a href="#" class="forgot-password">忘记密码？</a>
        </div>

        <button type="submit" class="login-button" :disabled="isLoading">
          {{ isLoading ? '登录中...' : '登录' }}
        </button>
      </form>

      <div class="social-login">
        <p>或使用以下方式登录</p>
        <div class="social-icons">
          <button class="social-btn google">
            <font-awesome-icon :icon="['fab', 'google']" size="lg"/>
          </button>
          <button class="social-btn github">
            <font-awesome-icon :icon="['fab', 'github']" size="lg"/>
          </button>
          <button class="social-btn wechat">
            <font-awesome-icon :icon="['fab', 'weixin']" size="lg"/>
          </button>
        </div>
      </div>

      <div class="register-link">
        还没有账户？ <a href="#">立即注册</a>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref} from 'vue'
import {useRouter} from 'vue-router'
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome'

const router = useRouter()
const username = ref('')
const password = ref('')
const rememberMe = ref(false)
const isLoading = ref(false)

const handleLogin = async () => {
  if (!username.value || !password.value) return

  try {
    isLoading.value = true
    // TODO: 实现登录逻辑
    await new Promise(resolve => setTimeout(resolve, 1500)) // 模拟登录请求
    await router.push('/')
  } catch (error) {
    console.error('登录失败:', error)
  } finally {
    isLoading.value = false
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.login-box {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.login-header h2 {
  color: #333;
  font-size: 28px;
  margin-bottom: 8px;
}

.login-header p {
  color: #666;
  font-size: 16px;
}

.login-form {
  margin-bottom: 30px;
}

.form-group {
  position: relative;
  margin-bottom: 25px;
}

.form-group input {
  width: 93%;
  padding: 12px;
  border: 2px solid #e1e1e1;
  border-radius: 10px;
  font-size: 16px;
  transition: all 0.3s ease;
  background: transparent;
}

.form-group input:focus {
  outline: none;
  border-color: #667eea;
}

.focus-border {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background-color: #667eea;
  transition: all 0.3s ease;
}

.form-group input:focus ~ .focus-border {
  width: 100%;
}

.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.remember-me {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #666;
  cursor: pointer;
}

.remember-me input[type="checkbox"] {
  accent-color: #667eea;
}

.forgot-password {
  color: #667eea;
  text-decoration: none;
  font-size: 14px;
  transition: color 0.3s ease;
}

.forgot-password:hover {
  color: #764ba2;
}

.login-button {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.login-button:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.login-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.social-login {
  text-align: center;
  margin-top: 30px;
  padding-top: 30px;
  border-top: 1px solid #e1e1e1;
}

.social-login p {
  color: #666;
  margin-bottom: 20px;
  font-size: 14px;
}

.social-icons {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.social-btn {
  width: 45px;
  height: 45px;
  border: none;
  border-radius: 50%;
  background: #f5f5f5;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: inherit;
}

.social-btn svg {
  width: 20px;
  height: 20px;
}

.social-btn:hover {
  transform: translateY(-2px);
}

.social-btn.google {
  color: #DB4437 !important;
}

.social-btn.github {
  color: #333 !important;
}

.social-btn.wechat {
  color: #07C160 !important;
}

.social-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.register-link {
  text-align: center;
  margin-top: 30px;
  color: #666;
}

.register-link a {
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.3s ease;
}

.register-link a:hover {
  color: #764ba2;
}

@media (max-width: 480px) {
  .login-box {
    padding: 30px 20px;
  }

  .login-header h2 {
    font-size: 24px;
  }

  .form-group input {
    font-size: 14px;
  }
}
</style>
